package Entity;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;

import Controllers.GlobalData;
import Controllers.GenericToolsForController.PDFfile;

public class TestingFailureReport  extends Report{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	Worker creator;	 //override reports user


     String strHeadline = "Testing Failure Report for ReEvaluation: ";
	 String strDateHeadline = "Generated On: ";
	 String strRequestId = null; 
	 String strDescriptionHeadlin = "Description for failure:";
	
	 public TestingFailureReport(Request request, String strDescription) throws IOException 
		{
		    this.type = ReportType.TESTING;
			this.setCreator((Worker)GlobalData.user);
			this.dateOfCreation = Calendar.getInstance().getTime();
			String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
			String currentDir = System.getProperty("user.dir");
			String path = currentDir+"\\";
			File dir=new File(path);
			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			path = (path + (creator.getUsername().replaceAll(" ", "_").replaceAll(":", "_"))+"\\");
			 dir=new File(path);
			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			path = path +"tmpFiles\\";
			 dir=new File(path);

			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			String strFileName = new String(path+"temp_eval_report"+creator.toString()+" generated "+ mydate.replaceAll(" ", "_").replaceAll(":", "_")+request.getRequestId());
			file = new File(strFileName);
			BufferedWriter writer = null;
			try
			{
				writer = new BufferedWriter( new FileWriter( file));
				writer.write(strHeadline+creator.toString()+"\n\n");
				writer.write(strDateHeadline+mydate+"\n" );
				writer.write(strDescriptionHeadlin+strDescription+"\n\n");           
			}
			catch ( IOException e)
			{
			}
			finally
			{
				try
				{
					if ( writer != null)
						writer.close( );
				}
				catch ( IOException e)
				{
				}
		     }
			this.pdfFile = new PDFfile(this,strFileName+".pdf");			
		}
	public Worker getCreator() {
		return creator;
	}

	public void setCreator(Worker creator) {
		this.creator = creator;
	}
	 
	
	
	
	
	
	
	
	

}
